var url = require('url')
var http = require('http')
var server = http.createServer();

var notifyMap = [];
var count = 1;
var readInfoPos = 1;
var key, value;
var responseBlock;

function getResponseJsonMessage(url){
	var message;
	
	if(url.path === '/sendMessageByUserIds'){
		message = {msg: 'message send success!'};
	} else if(url.path === '/getNotifyInfo'){
		key = "data" + readInfoPos;
		message = {msg: notifyMap[key]};
		
		readInfoPos++;
		if(readInfoPos > count){
			readInfoPos = count;
		}
	} else {
		message = {msg:404};
	}
	
	return message;
}

server.on('request', function(request, response){
	request.on("data", function(data){
		//console.log("request.on获取的post数据= " + data);
		key = "data" + count;
		notifyMap[key] = data.toString();
		count++;
	});
	
	if('url' in request) {
		console.log('path true')
		response.writeHead(200, {'Content-Type': 'application/json; charset=utf-8'});
		response.write(JSON.stringify(getResponseJsonMessage(url.parse(request.url), response)), 'utf-8');
	} else {
		response.writeHead(404, {'Content-Type': 'application/json; charset=utf-8'});
		response.write('not find page');
	}
	
	response.end();
});

server.listen(80, function(){
	console.log('server running............');
});






















